home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ov143b.zip / STRING.C < prev    next >
C/C++ Source or Header  |  1993-01-04  |  1KB  |  62 lines

  1. /*  005  8-Jun-87  string.c
  2.  
  3.         Common string related functions.
  4.  
  5.         Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  6. */
  7.  
  8. #ifndef NULL
  9. #define NULL (0)
  10. #endif
  11.  
  12. #ifdef LINT_ARGS
  13. #include <memory.h>
  14. #endif
  15.  
  16.  
  17. /*****************************************************************************
  18.                               C A T N S T R
  19.  *****************************************************************************/
  20.  
  21. char *
  22. catnstr(s1,s2,max)     /* concat s2 to s1 (or as much as will fit) */
  23. char *s1, *s2;
  24. int max;
  25. {
  26.    int l1, l2;
  27.  
  28.    if ((l1 = strlen(s1)) + (l2 = strlen(s2)) <= max)
  29.       strcat(s1,s2);
  30.    else
  31.       if (l1 < max)
  32.          strncat(s1,s2,max-l1);
  33.  
  34.    return(s1);
  35. }
  36.  
  37.  
  38. /*****************************************************************************
  39.                             S T R C P Y F I L L
  40.  *****************************************************************************/
  41.  
  42. char *
  43. strcpyfill(to,from,fldlen,fillch)      /* copy a string with char fill */
  44. char *from;
  45. register char *to;
  46. int fldlen, fillch;
  47. {
  48.    char *to_where;
  49.    register int len;
  50.  
  51.    to_where = to;
  52.    len = strlen(from);
  53.  
  54.    if (len < fldlen) {
  55.       strncpy(to,from,len);
  56.       memset(to+len,fillch,fldlen-len);
  57.    } else
  58.      strncpy(to,from,fldlen);
  59.  
  60.    return(to_where);
  61. }
  62.